<?php
/* @var $this UsuarioController */
/* @var $model Usuario */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'usuario-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
	'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'nome'); ?>
		<?php echo $form->textField($model,'nome',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'nome'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'sobrenome'); ?>
		<?php echo $form->textField($model,'sobrenome',array('size'=>40,'maxlength'=>40)); ?>
		<?php echo $form->error($model,'sobrenome'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'rg'); ?>
		<?php echo $form->textField($model,'rg',array('size'=>15,'maxlength'=>15)); ?>
		<?php echo $form->error($model,'rg'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'foto'); ?>
		<?php 
			if(!$model->isNewRecord)
			{
				echo CHtml::image(Yii::app()->baseUrl . '/images/foto/' . $model->foto, 'Perfil', array('width' => 100));
				echo "<br />";
				echo $form->radioButtonList($model, 'alterarFoto', array(0 => 'Não', 1 => 'Sim'), array(
					'labelOptions' => array('style' => 'display:inline'),
					'separator' => ' '
				));
  				echo "<br />";
			}
			echo $form->fileField($model,'foto',array('size'=>60,'maxlength'=>60)); 
		?>
		<?php echo $form->error($model,'foto'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'sexo'); ?>
		<?php 
			if(!isset($model->sexo))
				$model->sexo = 0;	
			echo $form->radioButtonList($model,'sexo', array(0 => 'Feminino', 1 => 'Masculino'), array(
				'labelOptions'=>array('style'=>'display:inline'),
				'separator' => ' '
			));
		?>
		<?php echo $form->error($model,'sexo'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'profissao_id'); ?>
		<?php 
			$profissao = Profissao::model()->findAll();
			echo $form->dropDownList($model,'profissao_id', CHtml::listData($profissao, 'id', 'nome')); 
		?>
		<?php echo $form->error($model,'profissao_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'tipoDocumentounico_id'); ?>
		<?php 
			$tipoDocumento = Tipodocumentounico::model()->findAll();
			echo $form->dropDownList($model,'tipoDocumentounico_id', CHtml::listData($tipoDocumento, 'id', 'nome')); 
		?>
		<?php echo $form->error($model,'tipoDocumentounico_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'documento'); ?>
		<?php echo $form->textField($model,'documento',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'documento'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'estadocivil_id'); ?>
		<?php 
			$estadoCivil = Estadocivil::model()->findAll();
			echo $form->dropDownList($model,'estadocivil_id', CHtml::listData($estadoCivil, 'id', 'nome')); 
		?>
		<?php echo $form->error($model,'estadocivil_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'data_nascimento'); ?>
		<?php 
			echo $form->dropDownList($model,'dia', Controller::getDias());
			echo $form->dropDownList($model,'mes', Controller::getMeses());
			echo $form->dropDownList($model,'ano', Controller::getCemAnos());
		?>
		<?php echo $form->error($model,'data_nascimento'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'login'); ?>
		<?php echo $form->textField($model,'login',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'login'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php 
			if(!$model->isNewRecord)
				$model->password = '';
			
			echo $form->passwordField($model,'password',array('size'=>40,'maxlength'=>40)); 
		?>
		<?php echo $form->error($model,'password'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'level'); ?>
		<?php 
			$tipoUsuario = Tipousuario::model()->findAll();
			echo $form->dropDownList($model,'level', CHtml::listData($tipoUsuario, 'id', 'nome')); 
		?>
		<?php echo $form->error($model,'level'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php 
			echo $form->dropDownList($model,'status', array(0 => 'Inativo', 1 => 'Ativo')); 
		?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<?php
		if(!$model->isNewRecord)
		{
			/*
			$colorBox = $this->widget('application.extensions.colorpowered.JColorBox');
			
			$colorBox
			    ->addInstance('.colorBoxEndereco', array('iframe'=>true, 'width'=>'80%', 'height'=>'80%'));
			*/
			
			echo CHtml::link('Cadastro Endereco', array('endereco/createEndereco', 'id' => base64_encode($model->id), 'return' => base64_encode('usuario/update')), array('class' => 'colorBoxEndereco'));

			$modelEndereco =Endereco::model();
			$this->widget('zii.widgets.grid.CGridView', array(
				'id'=>'endereco-grid',
				'dataProvider'=>$modelEndereco->search(array(
					'usuario_id' => $model->id
				)),
				'filter'=>$modelEndereco,
				'columns'=>array(
					'bairro',
					'numero',
					'cep',
					'complemento',
					/*
					'usuario_id',
					'pais_id',
					'uf_id',
					'cidade_id',
					'excluido',
					'dataCadastro',
					*/
					array(
						'class'=>'CButtonColumn',
						'template'=>'{update} {view} {delete}',
				        'buttons'=>array (
				            'update'=> array(
				                'label'=>'edit',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/update", array("id"=>$data->id, "uid" => $data->usuario_id))',
				                'options'=>array('class'=>'icon-edit' ),
				            ),
				            'view'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/view", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-search' ),
				            ),
				            'delete'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/delete", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-remove' ),
				            ),
				        ),
					),
				),
			));
			
			echo CHtml::link('Cadastro Telefone', array('telefone/createTelefone', 'id' => base64_encode($model->id), 'return' => base64_encode('usuario/update')), array('class' => 'colorBoxEndereco'));
			
			$telefoneModel = Telefone::model();
			$this->widget('zii.widgets.grid.CGridView', array(
				'id'=>'telefone-grid',
				'dataProvider'=>$telefoneModel->search(),
				'filter'=>$telefoneModel,
				'columns'=>array(
					'ddd',
					'numero',
					array(
						'name' => 'resumo',
						'value' => 'Telefone::getNomeResumo($data->resumo)'
					),//0 = Casa, 1=Comercio, 2=Celular
					array(
						'class'=>'CButtonColumn',
						'template'=>'{update} {view} {delete}',
				        'buttons'=>array (
				            'update'=> array(
				                'label'=>'edit',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("telefone/update", array("id"=>$data->id, "uid" => $data->usuario_id))',
				                'options'=>array('class'=>'icon-edit' ),
				            ),
				            'view'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/view", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-search' ),
				            ),
				            'delete'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/delete", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-remove' ),
				            ),
				        ),
					),
				),
			));
			
			echo CHtml::link('Cadastro Endereco Virtual', array('enderecovirtual/createEnderecoVirtual', 'id' => base64_encode($model->id), 'return' => base64_encode('usuario/update')), array('class' => 'colorBoxEndereco'));
			
			$enderecoVirtualModel = Enderecovirtual::model();
			$this->widget('zii.widgets.grid.CGridView', array(
				'id'=>'enderecovirtual-grid',
				'dataProvider'=>$enderecoVirtualModel->search(),
				'filter'=>$enderecoVirtualModel,
				'columns'=>array(
					'nome',
					array(
						'name' => 'tipoEnderecoVirtual_id',
						'value' => 'Tipoenderecovirtual::getNameTipoEndereco($data->tipoEnderecoVirtual_id)'
					),
					array(
						'name' => 'dataCadastro',
						'value' => 'date("d/m/Y H:i:s", strtotime($data->dataCadastro))'
					),
					array(
						'class'=>'CButtonColumn',
						'template'=>'{update} {view} {delete}',
				        'buttons'=>array (
				            'update'=> array(
				                'label'=>'edit',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("enderecoVirtual/update", array("id"=>$data->id, "uid" => $data->usuario_id))',
				                'options'=>array('class'=>'icon-edit' ),
				            ),
				            'view'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/view", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-search' ),
				            ),
				            'delete'=>array(
				                'label'=>'',
				                'imageUrl'=>'',
				                'url'=>'Yii::app()->createUrl("endereco/delete", array("id"=>$data->id))',
				                'options'=>array( 'class'=>'icon-remove' ),
				            ),
				        ),
					),
				),
			));
		}
	?>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->